package cn.bjit.compoent;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MailServiceImpl implements MailService {


    @Autowired
    private JavaMailSender javaMailSender;
   @Value("${spring.mail.from}")
    private String from;

    /**
     *
     * @param to  接收者的邮箱
     * @param subject   主题
     * @param content   内容
     */
    @Override
    public void sendSimpleMail(String to, String subject, String content) {
        //1，创建SimpleMailMessage对象
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //发邮件的那个人 我在配置里面
        mailMessage.setFrom(from);
        //接收人
        mailMessage.setTo(to);
        //主题
        mailMessage.setSubject(subject);
        //内容
        mailMessage.setText(content);
        //开始发送
        javaMailSender.send(mailMessage);
        log.info("邮件发送成功！{}",mailMessage.toString());
    }
}
